package com.central.scheduler.master.processor;

import com.central.scheduler.remote.command.Command;
import com.central.scheduler.remote.command.CommandType;
import com.central.scheduler.remote.command.TaskKillResponseCommand;
import com.central.scheduler.remote.processor.NettyRequestProcessor;
import com.central.scheduler.common.utils.JSONUtils;
import com.google.common.base.Preconditions;
import io.netty.channel.Channel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author Tindy
 * @date 2021/11/1
 * @describe
 *  task response processor
 */
public class TaskKillResponseProcessor implements NettyRequestProcessor {

    private final Logger logger = LoggerFactory.getLogger(TaskKillResponseProcessor.class);

    /**
     * task final result response
     * need master process , state persistence
     *
     * @param channel channel
     * @param command command
     */
    @Override
    public void process(Channel channel, Command command) {
        Preconditions.checkArgument(CommandType.TASK_KILL_RESPONSE == command.getType(), String.format("invalid command type : %s", command.getType()));

        TaskKillResponseCommand responseCommand = JSONUtils.parseObject(command.getBody(), TaskKillResponseCommand.class);
        logger.info("received task kill response command : {}", responseCommand);
    }

}